package com.yunxin.yundubbo.util;

import java.lang.reflect.Method;

public class CustomTypeDetector {

    /**
     * 判断是否为自定义对象类型
     */
    public static boolean isCustomObjectType(Method method) {
        Class<?> returnType = method.getReturnType();

        // 排除基础类型和常用系统类型
        if (returnType.isPrimitive() ||
                isBasicJavaType(returnType) ||
                returnType.isArray()) {
            return false;
        }

        // 检查包名，排除java、javax、sun等系统包
        String packageName = returnType.getPackage() != null ?
                returnType.getPackage().getName() : "";

        return !packageName.startsWith("java.") &&
                !packageName.startsWith("javax.") &&
                !packageName.startsWith("sun.") &&
                !packageName.startsWith("com.sun.");
    }

    private static boolean isBasicJavaType(Class<?> clazz) {
        return clazz.equals(String.class) ||
                clazz.equals(Integer.class) ||
                clazz.equals(Long.class) ||
                clazz.equals(Double.class) ||
                clazz.equals(Float.class) ||
                clazz.equals(Boolean.class) ||
                clazz.equals(Character.class) ||
                clazz.equals(Byte.class) ||
                clazz.equals(Short.class) ||
                clazz.equals(Void.class) ||
                clazz.equals(Object.class);
    }
}
